package com.lanou.controller;

import com.github.pagehelper.PageInfo;
import com.lanou.entity.ClassQaAnswer;
import com.lanou.service.ClassQaAnswerService;
import com.lanou.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @ClassName ClassQaAnswerController
 * @Description TODO
 * @Author cuiruitong
 * @Date 2025年08月14日 21:09
 * @Version 1.0
 */
@RestController
@RequestMapping("classQaAnswer")
public class ClassQaAnswerController {
    @Autowired
    private ClassQaAnswerService classQaAnswerService;
    //根据问题id查询所有问题
    @GetMapping("getAllAnswer")
    public R getAnswer(int questionId,@RequestParam(required = false,defaultValue = "1")int pageNum,@RequestParam(required = false,defaultValue = "5") int pageSize){
        PageInfo<ClassQaAnswer> classQaAnswerList = classQaAnswerService.getClassQaAnswerList(questionId, pageNum, pageSize);
        return R.ok(classQaAnswerList);

    }
    //添加问题答案
    @PostMapping
    public R updateAnswer(@RequestBody ClassQaAnswer classQaAnswer){

        classQaAnswer.setTime(new Date());
        int i = classQaAnswerService.addClassQaAnswer(classQaAnswer);
        System.out.println(classQaAnswer);
        if(i>0){
            return R.ok();
        }else {
            return R.fail("添加失败");
        }
    }
}
